package com.health.tablebean.webservice;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.health.db.FDbManager;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.CHILD_ONE2THREE_YEAR_OLD;
import com.health.tablebean.CHILD_TCMHM_ONE2THREE;
import com.health.viewscontrols.NovaApplication;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 月龄儿童家庭访视实体类
 *
 * @author wangxiangyi
 * @date 2018/4/16
 */
public class MonthsChildHomeVisit {
    /**
     * 儿童体重的测量值，计量单位为kg
     */
    private String avoirdupois;
    /**
     * 随访日期
     */
    private String visitDate;
    /**
     * 年龄别体重评价结果代码，
     * DM01-39_1 上，
     * DM01-39_2 中，
     * DM01-39_3 下
     */
    private String ageAvoirdupois;
    /**
     * 身长(cm)
     */
    private String stature;
    /**
     * 年龄别身高评价结果代码，
     * DM01-39_1 上，
     * DM01-39_2 中，
     * DM01-39_3 下
     */
    private String ageStature;
    /**
     * 面色检查结果代码,
     * DM05-14_2_1 红润，
     * DM05-14_2_2 其他
     */
    private String complexion;
    /**
     * 皮肤检查结果代码，
     * DM01-40_1 异常，
     * DM01-40_2 未见异常
     */
    private String skinCheck;
    /**
     * 前囟闭合标志
     * DM05-16_1_1 闭合，
     * DM05-16_1_2 未闭合
     */
    private String bregmaState;
    /**
     * 前囟横径的测量值，计量单位为cm
     */
    private String bregmaSize1;
    /**
     * 前囟纵径的测量值，计量单位为cm
     */
    private String bregmaSize2;
    /**
     * 可疑佝偻病体征代码组合
     * DM05-19_3_1	无
     * DM05-19_3_2	肋串珠
     * DM05-19_3_3	肋软骨沟
     * DM05-19_3_4	鸡胸
     * DM05-19_3_5	手足镯
     * DM05-19_3_6	O型腿
     * DM05-19_3_7	X型腿
     */
    private String rachitis;
    /**
     * 胸部听诊检查结果
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String heartCheck;
    /**
     * 腹部触诊检查结果
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String bellyCheck;
    /**
     * 四肢活动度标志
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String limbDisease;
    /**
     * 肛门/外生殖器检查结果
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String genitaliaCheck;
    /**
     * 每天户外活动时间，计量单位为小时
     */
    private String outdoorActivity;
    /**
     * 服用维生素D 单位为（IU/d）
     */
    private String appendD;
    /**
     * 12月岁发育评估：
     * DM05-26_4_1	呼唤名字无反应，
     * DM05-26_4_2	不会模仿“再见”或“欢迎”动作，
     * DM05-26_4_3	不会用拇食指对捏小物品，
     * DM05-26_4_4	不会扶物站立
     * <p>
     * 18月岁发育评估：
     * DM05-26_5_1	不会有意识叫“爸爸”或“妈妈”，
     * DM05-26_5_2	不会按要求指人或物，
     * DM05-26_5_3	与人无目光交流，
     * DM05-26_5_4	不会独走
     * <p>
     * 24月岁发育评估：
     * DM05-26_6_1	不会说3个物品的名称，
     * DM05-26_6_2	不会按吩咐做简单事情，
     * DM05-26_6_3	不会用勺吃饭，
     * DM05-26_6_4	不会扶栏上楼梯/台阶
     * <p>
     * 30月岁发育评估：
     * DM05-26_7_1	不会说2-3个字的短语，
     * DM05-26_7_2	兴趣单一、刻板，
     * DM05-26_7_3	不会示意大小便，
     * DM05-26_7_4	不会跑
     */
    private String growthCheck;
    /**
     * 标识在对儿童进行两次随访之间是否有患病,
     * DM01-11_1 无，
     * DM01-11_2有
     */
    private String betweenVisitDisease;
    /**
     * 二次体检间肺炎次数
     */
    private String pneumoniaNum;
    /**
     * 二次体检间腹泻次数
     */
    private String diarrheaNum;
    /**
     * 二次体检间外伤次数
     */
    private String traumaNum;
    /**
     * 其他疾病描述
     */
    private String otherDisease;
    /**
     * 转诊标志：
     * DM01-11_1 无，
     * DM01-11_2有
     */
    private String outDiagnose;
    /**
     * 转诊原因、转诊机构及科室
     */
    private Rollout rollOut;
    /**
     * 儿童健康指导类别代码：
     * DM05-04_1 科学喂养，
     * DM05-04_3 生长发育，
     * DM05-04_4 疾病预防，
     * DM05-04_5 预防伤害，
     * DM05-04_6 口腔保健，
     * DM05-04_9 其他
     */
    private String childrenGuideType;
    /**
     * 指导其他
     */
    private String guideOther;
    /**
     * 下次随访日期
     */
    private String nextVisitDate;
    /**
     * 随访医生签名
     */
    private String reportDoctor;
    /**
     * 创建人
     */
    private String creater;
    /**
     * 创建机构
     */
    private String createorg;
    /**
     * 城乡居民健康档案编号
     */
    private String personalid;
    /**
     * 月龄
     */
    private String age;
    /**
     * 耳外观检查结果，
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String auris;
    /**
     * 步态异常标志,
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String gaitMark;
    /**
     * 血红蛋白值
     */
    private String hgb;
    /**
     * 听力,
     * DM01-30_1 通过，
     * DM01-30_2 未通过
     */
    private String leftHearing;
    /**
     * 完整度
     */
    private String wzd;
    /**
     * 眼外观检查结果,
     * DM01-40_1 未见异常，
     * DM01-40_2 异常
     */
    private String eye;
    /**
     * 乳牙萌出的数量，计量单位为颗
     */
    private String babyTeeth2;
    /**
     * 儿童龋齿的数量，计量单位为颗
     */
    private String babyTeeth3;
    /**
     * 中医药健康管理服务
     * DM200-04_1	中医饮食调养指导
     * DM200-04_2	中医起居调摄指导
     * DM200-04_3	传授摩腹、捏脊方法
     * DM200-04_0	其他
     */
    private String res7;
    /**
     * 中医药健康管理服务其他
     */
    private String res8;
    /**
     * 身份证（现做证件号码）
     */
    private String cardid;

    public String getAvoirdupois() {
        return avoirdupois;
    }

    public void setAvoirdupois(String avoirdupois) {
        this.avoirdupois = avoirdupois;
    }

    public String getVisitDate() {
        return visitDate;
    }

    public void setVisitDate(String visitDate) {
        this.visitDate = visitDate;
    }

    public String getAgeAvoirdupois() {
        return ageAvoirdupois;
    }

    public void setAgeAvoirdupois(String ageAvoirdupois) {
        this.ageAvoirdupois = ageAvoirdupois;
    }

    public String getStature() {
        return stature;
    }

    public void setStature(String stature) {
        this.stature = stature;
    }

    public String getAgeStature() {
        return ageStature;
    }

    public void setAgeStature(String ageStature) {
        this.ageStature = ageStature;
    }

    public String getComplexion() {
        return complexion;
    }

    public void setComplexion(String complexion) {
        this.complexion = complexion;
    }

    public String getSkinCheck() {
        return skinCheck;
    }

    public void setSkinCheck(String skinCheck) {
        this.skinCheck = skinCheck;
    }

    public String getBregmaState() {
        return bregmaState;
    }

    public void setBregmaState(String bregmaState) {
        this.bregmaState = bregmaState;
    }

    public String getBregmaSize1() {
        return bregmaSize1;
    }

    public void setBregmaSize1(String bregmaSize1) {
        this.bregmaSize1 = bregmaSize1;
    }

    public String getBregmaSize2() {
        return bregmaSize2;
    }

    public void setBregmaSize2(String bregmaSize2) {
        this.bregmaSize2 = bregmaSize2;
    }

    public String getRachitis() {
        return rachitis;
    }

    public void setRachitis(String rachitis) {
        this.rachitis = rachitis;
    }

    public String getHeartCheck() {
        return heartCheck;
    }

    public void setHeartCheck(String heartCheck) {
        this.heartCheck = heartCheck;
    }

    public String getBellyCheck() {
        return bellyCheck;
    }

    public void setBellyCheck(String bellyCheck) {
        this.bellyCheck = bellyCheck;
    }

    public String getLimbDisease() {
        return limbDisease;
    }

    public void setLimbDisease(String limbDisease) {
        this.limbDisease = limbDisease;
    }

    public String getGenitaliaCheck() {
        return genitaliaCheck;
    }

    public void setGenitaliaCheck(String genitaliaCheck) {
        this.genitaliaCheck = genitaliaCheck;
    }

    public String getOutdoorActivity() {
        return outdoorActivity;
    }

    public void setOutdoorActivity(String outdoorActivity) {
        this.outdoorActivity = outdoorActivity;
    }

    public String getAppendD() {
        return appendD;
    }

    public void setAppendD(String appendD) {
        this.appendD = appendD;
    }

    public String getGrowthCheck() {
        return growthCheck;
    }

    public void setGrowthCheck(String growthCheck) {
        this.growthCheck = growthCheck;
    }

    public String getBetweenVisitDisease() {
        return betweenVisitDisease;
    }

    public void setBetweenVisitDisease(String betweenVisitDisease) {
        this.betweenVisitDisease = betweenVisitDisease;
    }

    public String getPneumoniaNum() {
        return pneumoniaNum;
    }

    public void setPneumoniaNum(String pneumoniaNum) {
        this.pneumoniaNum = pneumoniaNum;
    }

    public String getDiarrheaNum() {
        return diarrheaNum;
    }

    public void setDiarrheaNum(String diarrheaNum) {
        this.diarrheaNum = diarrheaNum;
    }

    public String getTraumaNum() {
        return traumaNum;
    }

    public void setTraumaNum(String traumaNum) {
        this.traumaNum = traumaNum;
    }

    public String getOtherDisease() {
        return otherDisease;
    }

    public void setOtherDisease(String otherDisease) {
        this.otherDisease = otherDisease;
    }

    public String getOutDiagnose() {
        return outDiagnose;
    }

    public void setOutDiagnose(String outDiagnose) {
        this.outDiagnose = outDiagnose;
    }

    public Rollout getRollOut() {
        return rollOut;
    }

    public void setRollOut(Rollout rollOut) {
        this.rollOut = rollOut;
    }

    public String getChildrenGuideType() {
        return childrenGuideType;
    }

    public void setChildrenGuideType(String childrenGuideType) {
        this.childrenGuideType = childrenGuideType;
    }

    public String getGuideOther() {
        return guideOther;
    }

    public void setGuideOther(String guideOther) {
        this.guideOther = guideOther;
    }

    public String getNextVisitDate() {
        return nextVisitDate;
    }

    public void setNextVisitDate(String nextVisitDate) {
        this.nextVisitDate = nextVisitDate;
    }

    public String getReportDoctor() {
        return reportDoctor;
    }

    public void setReportDoctor(String reportDoctor) {
        this.reportDoctor = reportDoctor;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getCreateorg() {
        return createorg;
    }

    public void setCreateorg(String createorg) {
        this.createorg = createorg;
    }

    public String getPersonalid() {
        return personalid;
    }

    public void setPersonalid(String personalid) {
        this.personalid = personalid;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getAuris() {
        return auris;
    }

    public void setAuris(String auris) {
        this.auris = auris;
    }

    public String getGaitMark() {
        return gaitMark;
    }

    public void setGaitMark(String gaitMark) {
        this.gaitMark = gaitMark;
    }

    public String getHgb() {
        return hgb;
    }

    public void setHgb(String hgb) {
        this.hgb = hgb;
    }

    public String getLeftHearing() {
        return leftHearing;
    }

    public void setLeftHearing(String leftHearing) {
        this.leftHearing = leftHearing;
    }

    public String getWzd() {
        return wzd;
    }

    public void setWzd(String wzd) {
        this.wzd = wzd;
    }

    public String getEye() {
        return eye;
    }

    public void setEye(String eye) {
        this.eye = eye;
    }

    public String getBabyTeeth2() {
        return babyTeeth2;
    }

    public void setBabyTeeth2(String babyTeeth2) {
        this.babyTeeth2 = babyTeeth2;
    }

    public String getBabyTeeth3() {
        return babyTeeth3;
    }

    public void setBabyTeeth3(String babyTeeth3) {
        this.babyTeeth3 = babyTeeth3;
    }

    public String getRes7() {
        return res7;
    }

    public void setRes7(String res7) {
        this.res7 = res7;
    }

    public String getRes8() {
        return res8;
    }

    public void setRes8(String res8) {
        this.res8 = res8;
    }

    public String getCardid() {
        return cardid;
    }

    public void setCardid(String cardid) {
        this.cardid = cardid;
    }

    /**
     * 12月龄内检查
     *
     * @param context 上下文
     * @param flag    1：12月龄
     *                2：18月龄
     *                3： 24月龄
     *                4： 30月龄
     * @return
     */
    public static List<MonthsChildHomeVisit> convertData(Context context, String flag) {
        List<MonthsChildHomeVisit> datas = new ArrayList<>();

        FDbManager fdb = FDbManager.getInstance(context);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        List<CHILD_ONE2THREE_YEAR_OLD> infos = fdb.findAllByWhere(CHILD_ONE2THREE_YEAR_OLD.class,
                "IS_UPDATE is not 'N'" + " AND CREATER='" + NovaApplication.getJgrno() + "' AND FLAG='" + flag + "'");

        if (infos != null && !infos.isEmpty()) {
            for (CHILD_ONE2THREE_YEAR_OLD info : infos) {
                MonthsChildHomeVisit data = new MonthsChildHomeVisit();
                /* 1：12月龄2：18月龄 3：24月龄 4：30月龄*/
                if ("1".equals(flag)) {
                    data.setAge("12");
                } else if ("2".equals(flag)) {
                    data.setAge("18");
                } else if ("3".equals(flag)) {
                    data.setAge("24");
                } else if ("4".equals(flag)) {
                    data.setAge("30");
                }
                /*查询档案编号*/
                List<ARCHIVE_BASEINFO> baseinfos = fdb.findAllByWhere(ARCHIVE_BASEINFO.class,
                        "IDCARD ='" + info.getIDCARD() + "'");
                /*设置档案编号*/
                if (null != baseinfos && baseinfos.size() > 0) {
                    data.setPersonalid(baseinfos.get(0).getARCHIVEID());
                } else {
                    data.setPersonalid("");
                }
                /*身份证号*/
                data.setCardid(TextUtils.isEmpty(info.getIDCARD()) ? "" : info.getIDCARD().toUpperCase());
                if (info.getFOLLOWUP_DATE() != null) {
                    /*随访日期*/
                    data.setVisitDate(formatter.format(info.getFOLLOWUP_DATE()));
                }
                /*体重*/
                data.setAvoirdupois(TextUtils.isEmpty(info.getWEIGHT()) ? "" : info.getWEIGHT());
                /*体重分析*/
                data.setAgeAvoirdupois(TextUtils.isEmpty(info.getWEIGHT_ANALYSIS()) ? "" : info.getWEIGHT_ANALYSIS());
                /*身长*/
                data.setStature(TextUtils.isEmpty(info.getSTATURE()) ? "" : info.getSTATURE());
                /*身长评价*/
                data.setAgeStature(TextUtils.isEmpty(info.getSTATURE_ANALYSIS()) ? "" : info.getSTATURE_ANALYSIS());
                /*面色*/
                data.setComplexion(TextUtils.isEmpty(info.getCOLOUR_FACE()) ? "" : info.getCOLOUR_FACE());
                /*皮肤*/
                data.setSkinCheck(TextUtils.isEmpty(info.getSKIN()) ? "" : info.getSKIN());
                /*前囟*/
                data.setBregmaState(TextUtils.isEmpty(info.getBREGMA()) ? "" : info.getBREGMA());
                /*前囟横经测量值*/
                data.setBregmaSize1(TextUtils.isEmpty(info.getBREGMA_LEFT()) ? "" : info.getBREGMA_LEFT());
                /*前囟纵经测量值*/
                data.setBregmaSize2(TextUtils.isEmpty(info.getBREGMA_RIGHT()) ? "" : info.getBREGMA_RIGHT());
                /*眼睛外观*/
                data.setEye(TextUtils.isEmpty(info.getEYE_APPEARANCE()) ? "" : info.getEYE_APPEARANCE());
                /*耳外观*/
                data.setAuris(TextUtils.isEmpty(info.getEAR_APPEARANCE()) ? "" : info.getEAR_APPEARANCE());
                /*听力*/
                data.setLeftHearing(TextUtils.isEmpty(info.getLISTENING()) ? "" : info.getLISTENING());
                /*出牙颗数*/
                data.setBabyTeeth2(TextUtils.isEmpty(info.getTEETH_DCN_LEFT()) ? "" : info.getTEETH_DCN_LEFT());
                /*儿童龋齿颗数*/
                data.setBabyTeeth3(TextUtils.isEmpty(info.getTEETH_DCN_RIGHT()) ? "" : info.getTEETH_DCN_RIGHT());
                /*胸部*/
                data.setHeartCheck(TextUtils.isEmpty(info.getHEART_LUNG()) ? "" : info.getHEART_LUNG());
                /*腹部*/
                data.setBellyCheck(TextUtils.isEmpty(info.getSTOMACH()) ? "" : info.getSTOMACH());
                /*四肢*/
                data.setLimbDisease(TextUtils.isEmpty(info.getFOUR_LIMB()) ? "" : info.getFOUR_LIMB());
                /*步态*/
                data.setGaitMark(TextUtils.isEmpty(info.getGAIT()) ? "" : info.getGAIT());
                /*可疑佝偻病体征*/
                data.setRachitis(TextUtils.isEmpty(info.getSUSPICIOUS_RICKETS()) ? "" : info.getSUSPICIOUS_RICKETS());
                /*血红蛋白值*/
                data.setHgb(TextUtils.isEmpty(info.getHEMOGLOBIN_VALUE()) ? "" : info.getHEMOGLOBIN_VALUE());
                /*户外活动*/
                data.setOutdoorActivity(TextUtils.isEmpty(info.getOUTDOOR_ACTIVITIES()) ? "" : info.getOUTDOOR_ACTIVITIES());
                /*服用维生素D*/
                data.setAppendD(TextUtils.isEmpty(info.getTAKING_VITAMINSD()) ? "" : info.getTAKING_VITAMINSD());
                /*发育评估*/
                data.setGrowthCheck(TextUtils.isEmpty(info.getAUXE_ESTIMATE_OTHER()) ? "" : info.getAUXE_ESTIMATE_OTHER());
                /*两次随访间患者情况*/
                data.setBetweenVisitDisease(TextUtils.isEmpty(info.getAMONG_TWO_FOLLOWUP()) ? "" : info.getAMONG_TWO_FOLLOWUP());
                /*肺炎*/
                data.setPneumoniaNum(TextUtils.isEmpty(info.getPNEUMONIA_FREQUEN()) ? "" : info.getPNEUMONIA_FREQUEN());
                /*腹泻*/
                data.setDiarrheaNum(TextUtils.isEmpty(info.getDIARRHOEA_FREQUEN()) ? "" : info.getDIARRHOEA_FREQUEN());
                /*外伤*/
                data.setTraumaNum(TextUtils.isEmpty(info.getTRAUMATISM_FREQUEN()) ? "" : info.getTRAUMATISM_FREQUEN());
                /*其他*/
                data.setOtherDisease(TextUtils.isEmpty(info.getAMONG_TWO_FOLLO_OTHER()) ? "" : info.getAMONG_TWO_FOLLO_OTHER());
                /*转诊建议*/
                data.setOutDiagnose(TextUtils.isEmpty(info.getREFERRAL_ADVICE()) ? "" : info.getREFERRAL_ADVICE());
                /*转诊原因、机构及科室*/
                Rollout rollOut = new Rollout();
                rollOut.setHpc(TextUtils.isEmpty(info.getREFERRAL_REASON()) ? "" : info.getREFERRAL_REASON());
                rollOut.setRollInRegion(TextUtils.isEmpty(info.getAGENCIES_DEPARTMENTS()) ? "" : info.getAGENCIES_DEPARTMENTS());
                data.setRollOut(rollOut);
                /*指导*/
                data.setChildrenGuideType(TextUtils.isEmpty(info.getGUIDANCE()) ? "" : info.getGUIDANCE());
                /*指导其他原因*/
                data.setGuideOther(TextUtils.isEmpty(info.getGUIDANCE_OTHER()) ? "" : info.getGUIDANCE_OTHER());

                /*查询中医药管理服务*/
                List<CHILD_TCMHM_ONE2THREE> infos2 = fdb.findAllByWhere(CHILD_TCMHM_ONE2THREE.class,
                        "IDCARD='" + info.getIDCARD() + "' AND FOLLOWUP_TYPE='" + flag + "'");
                /* 中医药健康管理服务*/
                if (null != infos2 && infos2.size() > 0) {
                    /*中医药健康管理服务*/
                    data.setRes7(infos2.get(infos2.size() - 1).getTCMHM());
                    /*中医药健康管理服务其他原因*/
                    data.setRes8(infos2.get(infos2.size() - 1).getTCMHM_OTHER());
                } else {
                    /*中医药健康管理服务*/
                    data.setRes7("");
                    /*中医药健康管理服务其他原因*/
                    data.setRes8("");
                }
                /*下次随访时间*/
                if (info.getNEXT_FOLLOWUP_DATE() != null) {
                    data.setNextVisitDate(formatter.format(info.getNEXT_FOLLOWUP_DATE()));
                }
                /*随访医生签名*/
                data.setReportDoctor(TextUtils.isEmpty(info.getLAST_UPDATE_BY()) ? "" : info.getLAST_UPDATE_BY());
                /*创建人*/
                data.setCreater(TextUtils.isEmpty(info.getCREATER()) ? "" : info.getCREATER());
                /*创建机构*/
                data.setCreateorg(TextUtils.isEmpty(info.getCREATEORG()) ? "" : info.getCREATEORG());

                /*添加list里面*/
                datas.add(data);
            }
        }
        return datas;
    }
}
